home *** CD-ROM | disk | FTP | other *** search
- /*
- * FednetCmp - Fednet file compression/decompression
- * Utility functions
- * Copyright (C) 2001 Chris Bazley
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public Licence as published by
- * the Free Software Foundation; either version 2 of the Licence, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public Licence for more details.
- *
- * You should have received a copy of the GNU General Public Licence
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- /* ANSI library files */
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdbool.h>
-
- /* RISC OS library files */
- #include "kernel.h"
- #include "toolbox.h"
- #include "event.h"
- #include "window.h"
- #include "saveas.h"
- #include "wimplib.h"
- #include "gadgets.h"
- #include "swis.h"
- #include "flex.h"
-
- /* My library files */
- #include "err.h"
- #include "msgtrans.h"
- #include "hourglass.h"
- #include "Macros.h"
- #include "FilePerc.h"
-
- /* Local headers */
- #include "Utils.h"
- #include "Main.h"
-
- /* ----------------------------------------------------------------------- */
- /* Public functions */
-
- _kernel_oserror *open_above_iconbar(unsigned int flags, ObjectId id, ObjectId parent, ComponentId parent_component)
- {
- /* Open window horizontally centred on pointer, above iconbar */
- WimpGetPointerInfoBlock pointerinfo;
- WindowShowObjectBlock showblock;
- WimpGetWindowStateBlock winstate;
- ObjectId win_id;
-
- THROW(wimp_get_pointer_info(&pointerinfo));
- THROW(saveas_get_window_id(0, id, &win_id));
- THROW(window_get_wimp_handle(0, win_id, &(winstate.window_handle)));
- THROW(wimp_get_window_state(&winstate));
-
- showblock.visible_area.xmin = pointerinfo.x - (winstate.visible_area.xmax - winstate.visible_area.xmin)/2;
- showblock.visible_area.ymin = 96 + (winstate.visible_area.ymax - winstate.visible_area.ymin);
- return toolbox_show_object(flags, id, Toolbox_ShowObject_TopLeft, &showblock, parent, parent_component);
- }
-
- /* ----------------------------------------------------------------------- */
-
- char *copystring(char *string)
- {
- /* copy string into newly allocated memory */
- char *ptr;
-
- ptr = malloc(strlen(string)+1);
- if(ptr == NULL)
- err_complain(0, msgs_global("NoMem"));
- else
- strcpy(ptr, string);
- return ptr;
- }
-
-
- /* ----------------------------------------------------------------------- */
-
- _kernel_oserror *showgadget(ObjectId window, ComponentId gadget)
- {
- int height;
- BBox pos;
- THROW(gadget_get_bbox(0, window, gadget, &pos));
- if(pos.ymin < 0) /* already shown */
- return NULL;
- /* shift the icon into the window to show the button */
- height = pos.ymax - pos.ymin;
- pos.ymin = -pos.ymin; /* implicitly preserves dist. icbottom-to-wintop */
- pos.ymax = pos.ymin+height; /* keep dist. icbottom-to-ictop */
- return gadget_move_gadget(0, window, gadget, &pos);
- }
-
- /* ----------------------------------------------------------------------- */
-
- _kernel_oserror *hidegadget(ObjectId window, ComponentId gadget)
- {
- int height;
- BBox pos;
- THROW(gadget_get_bbox(0, window, gadget, &pos));
- if(pos.ymin > 0) /* already hidden */
- return NULL;
- /* shift the icon off the top to show the button */
- height = pos.ymax - pos.ymin;
- pos.ymin = -pos.ymin; /* implicitly preserves dist. icbottom-to-wintop */
- pos.ymax = pos.ymin+height; /* keep dist. icbottom-to-ictop */
- return gadget_move_gadget(0, window, gadget, &pos);
- }
-
- /* ----------------------------------------------------------------------- */
-
- _kernel_oserror *set_gadget_faded(bool fade, ObjectId id, ComponentId gad)
- {
- unsigned int flags_settings;
-
- THROW(gadget_get_flags(0, id, gad, &flags_settings));
- if(fade) {
- if(FLAG_SET(flags_settings, Gadget_Faded))
- return NULL;
- flags_settings |= Gadget_Faded;
- }
- else {
- if(!FLAG_SET(flags_settings, Gadget_Faded))
- return NULL;
- flags_settings &= (~Gadget_Faded);
- }
- return gadget_set_flags(0, id, gad, flags_settings);
- }
-
- /* ----------------------------------------------------------------------- */
-
- _kernel_oserror *getscreencentre(int *centreX,int *centreY)
- {
- /* Get screen centre */
- _kernel_swi_regs regs;
- int XWindLimit,YWindLimit;
- int XEigFactor,YEigFactor;
-
- regs.r[0]=-1; /* current mode */
- regs.r[1]=11; /* no of x pixels on screen-1 */
- THROW(_kernel_swi(OS_ReadModeVariable,®s,®s));
- XWindLimit=regs.r[2];
-
- regs.r[0]=-1; /* current mode */
- regs.r[1]=12; /* no of y pixels on screen-1 */
- THROW(_kernel_swi(OS_ReadModeVariable,®s,®s));
- YWindLimit=regs.r[2];
-
- regs.r[0]=-1; /* current mode */
- regs.r[1]=4; /* X eigen factor */
- THROW(_kernel_swi(OS_ReadModeVariable,®s,®s));
- XEigFactor=regs.r[2];
-
- regs.r[0]=-1; /* current mode */
- regs.r[1]=5; /* Y eigen factor */
- THROW(_kernel_swi(OS_ReadModeVariable,®s,®s));
- YEigFactor=regs.r[2];
-
- *centreX = (XWindLimit<<XEigFactor)/2;
- *centreY = (YWindLimit<<YEigFactor)/2;
- return NULL;
- }
-
- /* ----------------------------------------------------------------------- */
-
- char *tail(char *pathname, int length)
- {
- char *ptr;
- int dotcount;
-
- ptr = (char *)((int)pathname + strlen(pathname)); /* terminator */
- dotcount = 0;
- while(ptr > pathname && dotcount<length) {
- ptr--; /* scan string backwards from terminator */
- if(*ptr == '.')
- dotcount++;
- }
- if(dotcount >= length)
- return (char *)((int)ptr + 1);
- return ptr;
- }
-
- /* ----------------------------------------------------------------------- */
-
- int delete_object_handler(int event_code, ToolboxEvent *event, IdBlock *id_block, void *handle)
- {
- /* Generic handler for deleting an object */
- RE(toolbox_delete_object(0, id_block->self_id));
-
- return 1; /* claim event */
- }
-
- /*
- * File loading routines
- */
-
- _kernel_oserror *load_compressed(char *filepath, flex_ptr buffer_anchor)
- {
- return perc_operation(FILEPERC_OP_DECOMP, filepath, 0, buffer_anchor);
- }
-
- /* ----------------------------------------------------------------------- */
-
- _kernel_oserror *load_plain(char *filepath, flex_ptr buffer_anchor)
- {
- return perc_operation(FILEPERC_OP_LOAD, filepath, 0, buffer_anchor);
- }
-